package cn.wolfcode.wms.page;

import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;
@Getter
@Setter
public class PageResult {
    private List<?> data;
    private Integer totalCount;
    private Integer currentPage;
    private Integer pageSize;
    private Integer prevPage;
    private Integer nextPage;
    private Integer totalPage;

    public PageResult(int totalCount, List<?> data, Integer currentPage, Integer pageSize) {
        this.totalCount = totalCount;
        this.data = data;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        if (totalCount <= pageSize) {
            prevPage = 1;
            totalPage = 1;
            nextPage = 1;
            return;
        }
        totalPage = totalCount % pageSize ==0 ? totalCount / pageSize  : totalCount / pageSize+1;
        prevPage = currentPage < 2 ? 1 : currentPage - 1;
        nextPage = currentPage < totalPage ? currentPage + 1 : totalPage;
    }
    public PageResult(Integer pageSize){
        this(0,Collections.EMPTY_LIST,1,pageSize);
    }

    /*public static PageResult empty(Integer pageSize) {
        return null;
    }*/
}
